import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server:{
    host:"0.0.0.0",
    port: 8668, //端口号
    open: true, //启动后是否自动打开浏览器
    proxy:{//通过代理实现跨域
      "/balanceApi":{//路径，作用就是替换域名
        target:"http://127.0.0.1:9873",//表示要替换的服务端地址
        changeOrigin:true,//开启代理，允许跨域请求数据
        secure:false,
        rewrite:(path) => path.replace(/^\/balanceApi/,""),
      },
      "/collectApi":{//路径，作用就是替换域名
        target:"http://127.0.0.1:7886",//表示要替换的服务端地址
        changeOrigin:true,//开启代理，允许跨域请求数据
        secure:false,
        rewrite:(path) => path.replace(/^\/collectApi/,""),
      },
      "/detectApi":{//路径，作用就是替换域名
        target:"http://127.0.0.1:5886",//表示要替换的服务端地址
        changeOrigin:true,//开启代理，允许跨域请求数据
        secure:false,
        rewrite:(path) => path.replace(/^\/detectApi/,""),
      },
      "/estimateApi":{//路径，作用就是替换域名
        target:"http://127.0.0.1:9886",//表示要替换的服务端地址
        changeOrigin:true,//开启代理，允许跨域请求数据
        secure:false,
        rewrite:(path) => path.replace(/^\/estimateApi/,""),
      },
      "/collectWS": {
        // target: 'ws://192.168.0.66:60601/',这是后端接口地址
        target: 'ws://127.0.0.1:7888',
        changeOrigin: true,
        ws: true,
        rewrite:(path) => path.replace(/~\/collectWS/,""),
      },
      "/detectWS": {
        // target: 'ws://192.168.0.66:60601/',这是后端接口地址
        target: 'ws://127.0.0.1:8888',
        changeOrigin: true,
        ws: true,
        rewrite:(path) => path.replace(/~\/detectWS/,""),
      },
      "/estimateWS": {
        // target: 'ws://192.168.0.66:60601/',这是后端接口地址
        target: 'ws://127.0.0.1:9888',
        changeOrigin: true,
        ws: true,
        rewrite:(path) => path.replace(/~\/estimateWS/,""),
      },
    },
  }
})
